import React, { Component } from 'react';
import "./Guanlishuju.scss"
class Guanlishuju extends Component {
    constructor(props) {
        super(props)
        this.state = {
            lo: [],
            ol: []
        }
    }
    componentDidMount() {
        this.abcd()
    }
    abcd=()=> {
        React.axios.get(`store-manage/w2003/goods-manage-g1/goods-info.php`).then(res => {
            this.setState({
                lo: res.data
            })
            
        })
    }
    // 删除
    aa = (index) => {
        if (window.confirm("你确定要删除吗")) {
            React.axios.get(`/store-manage/w2003/goods-manage-g1/goods-delete.php?goodsID=` + index).then(res => {
                
                alert(res.data)
                this.abcd()
            })
        }
    }
    // 修改
    ll=(b)=>{
        console.log(b);
        this.props.history.push({
            pathname:'/caozuo',
            a:b
        })
    }
    render() {
        return (
            <div>
                <table>
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>品牌</th>
                            <th>名称</th>
                            <th>型号</th>
                            <th>分类</th>
                            <th>入库时间</th>
                            <th>数量</th>
                            <th>单价</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {this.state.lo.map((b, index) => <tr key={b.goodsID}> <td>{b.goodsID}</td>
                            <td>{b.brand}</td><td>{b.goodsName}</td>
                            <td>{b.model}</td><td>{b.category}</td>
                            <td>{b.intoDatetime}</td><td>{b.quantity}</td>
                            <td>{b.price}</td><td><button onClick={()=>this.ll(b)}>修改</button><button onClick={() => this.aa(b.goodsID)} >删除</button></td></tr>)}
                    </tbody>
                </table>


            </div>
        );
    }
}

export default Guanlishuju;
